package hikari.persistence.handlersimpl;

import com.gooddies.wiring.annotations.WiringComponent;
import hikari.objects3d.Basic3dObject;
import hikari.objects3d.Camera3dObject;
import hikari.persistence.file.FileSection;
import hikari.persistence.persisthandlers.IPersistantObject3dReadHandler;
import hikari.persistence.persisthandlers.PersistantHandler;
import java.io.IOException;
import org.swig.jirr.ISceneManager;

@WiringComponent(singleton = true, lazy = true)
@PersistantHandler(sectionName = "cameraData")
public class CameraLoadHandler implements IPersistantObject3dReadHandler {

    private CameraLoadHandler() {
    }

    @Override
    public Basic3dObject read(ISceneManager sceneManager, Basic3dObject object, FileSection section) throws IOException {
        Camera3dObject camera = (Camera3dObject) object;
        float fov = section.readFloat(section.getChunk("fov"));
        float near = section.readFloat(section.getChunk("near"));
        float far = section.readFloat(section.getChunk("far"));
        float aspect = section.readFloat(section.getChunk("aspect"));
        camera.getRealCameraNode().setFOV(fov);
        camera.getRealCameraNode().setNearValue(near);
        camera.getRealCameraNode().setFarValue(far);
        camera.getRealCameraNode().setAspectRatio(aspect);
        return camera;
    }
}